
(ns win.activex
  (:require util.loader) ; must use this to get DLL path set correctly
  (:import [com.jacob.activeX ActiveXComponent]
           [com.jacob.com Dispatch Variant]))

(def get-property-functions
  {:default   #(.getProperty          %1 %2)
   :boolean   #(.getPropertyAsBoolean %1 %2)
   :byte      #(.getPropertyAsByte    %1 %2)
   :component #(.getPropertyComponent %1 %2)
   :int       #(.getPropertyInt       %1 %2)
   :string    #(.getPropertyString    %1 %2)
   })

(defn- set-property [x k v]
  (.setProperty x k v))

(defn- get-property
  ([x k]
    (.getProperty x k))
  ([x k t]
    (let [f (get-property-functions t)]
      (when-not f
        (throw (Exception. "Unknown property type %s" t)))
      (f x k))))

(defn activex [id & {:as properties}]
  (let [x (ActiveXComponent. id)]
    (when properties
      (doseq [[k v] properties]
        (set-property x k v)))
    x))

(def active-x activex)



